library(tidyverse)
library(plotly)
library(p8105.datasets)
library(lubridate)
data("rest_inspec")
Here is the code for the bar chart. It shows the count of Grade A restaurants in different cuisines.
gradeA_cuisine = rest_inspec |>
filter(grade == "A") |>
group_by(cuisine_description) |>
summarise(count = n()) |>
plot_ly(x = ~cuisine_description, y = ~count, color = ~cuisine_description, type = "bar", colors = "viridis")
gradeA_cuisine
Here is the code for the scatter plot. It shows the count of Grade A restaurants inspected in different year-month.
year_count = rest_inspec |>
filter(grade == "A") |>
mutate(inspection_date = as.Date(inspection_date),
year_month = format(inspection_date, format = "%Y-%m")) |>
group_by(year_month) |>
summarise(count = n()) |>
plot_ly(x = ~year_month, y = ~count, color = ~year_month, type = "scatter", mode = "markers", colors = "viridis")
year_count
Here is the code for the box plot. It gives the information about the restaurant score in respect to different boroughs.
boro_score = rest_inspec |>
drop_na(score, boro) |>
mutate(boro = fct_reorder(boro, score)) |>
plot_ly(x = ~boro, y = ~score, color = ~boro, type = "box", colors = "inferno")
boro_score